<div class="categories index">
<h2><?php __('Top Categories');?></h2>

	<div id="top">
		<?
		foreach($tops as $period) {
			?>
			<div class="period <?= $period['name'] ?>">
			<h3><?= $period['title'] ?></h3>
			<?
			echo $this->renderElement('top_categories', array('categories' => $period['data'], 'period'=>$period['name']));

			echo $html->link('View Archive', array('controller'=>'archive', 'action'=>$period['name'], $period['date']));
			?>
			</div><?
		}
		?>
	</div>

<h2>All Categories</h2>

<div class="paging">
	<?php echo $paginator->prev('<<');?>
 	<?php echo $paginator->numbers();?>
	<?php echo $paginator->next('>>');?>
</div>

<table class="categories index">
<tr>
	<th><?php echo $paginator->sort('name');?></th>
	<th><?php echo $paginator->sort('purchase_count');?></th>
	<th><?php echo $paginator->sort('All-time total', 'purchase_sum');?></th>
	<th><?php echo $paginator->sort('Last used', 'modified');?></th>
	<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($categories as $category):
	$class = null;
	if ($i++ % 2 == 0) {
		$class = ' class="altrow"';
	}
?>
	<tr<?php echo $class;?>>
		<td>
			<?php echo $html->link($category['Category']['name'], array('action'=>'view', $category['Category']['id'])); ?>
		</td>
		<td>
		<?= $category['Category']['purchase_count'] ?>
		</td>
		<td class="numeric">
		<?= $category['Category']['purchase_sum'] ?>
		</td>
		<td class="date numeric">
			<?= $time->format('dS M Y', $category['Category']['modified']) ?>
		</td>
		<td class="actions">
			<?php echo $html->link(__('Edit', true), array('action'=>'edit', $category['Category']['id'])); ?>
			<?php echo $html->link(__('Delete', true), array('action'=>'delete', $category['Category']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $category['Category']['id'])); ?>
		</td>
	</tr>
<?php endforeach; ?>
</table>
</div>
<div class="paging">
	<?php echo $paginator->prev('<<');?>
 	<?php echo $paginator->numbers();?>
	<?php echo $paginator->next('>>');?>
</div>
